<template>
  <div class="input-bar-wrapper">
    <el-input
      v-model="inputMessage"
      type="textarea"
      :rows="3"
      placeholder="您想问什么问题？"
      class="full-width-input"
      @keydown.enter.exact.prevent="handleSend"
    />
    <div class="scroll-percentage-input" v-if="scrollPercentage > 0">{{ scrollPercentage }}%</div>
    <el-button :type="inputMessage.trim() && !isRobotTyping ? 'primary' : 'default'" class="send-btn" :disabled="!inputMessage.trim() || isRobotTyping" @click="handleSend">
      <el-icon>
        <component :is="isRobotTyping ? CircleCloseFilled : ArrowUp" />
      </el-icon>
    </el-button>
  </div>
</template>

<script setup>
import { ref, defineEmits, defineProps } from 'vue'
import { ArrowUp, CircleCloseFilled } from '@element-plus/icons-vue'
const inputMessage = ref('')
const emit = defineEmits(['send'])

const props = defineProps({
  scrollPercentage: {
    type: Number,
    default: 0
  },
  isRobotTyping: {
    type: Boolean,
    default: false
  }
})

function handleSend() {
  const msg = inputMessage.value.trim()
  if (!msg || props.isRobotTyping) return
  emit('send', msg)
  inputMessage.value = ''
}
</script>

<style scoped>
.input-bar-wrapper {
  width: 100%;
  background: #f2f3f5;
  border-radius: 32px;
  border: none;
  position: relative;
  display: flex;
  align-items: center;
  margin-top: 32px;
}

.full-width-input {
  width: 100%;
}

:deep(.el-textarea__inner) {
  padding: 12px 50px 12px 16px;
  resize: none;
  border-radius: 16px;
  min-height: 56px !important;
  font-size: 16px;
  background: #fff;
  border: 1px solid #e6e6e6;
  color: #222;
  box-shadow: none;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
}
:deep(.el-textarea__inner::placeholder) {
  color: #999;
  opacity: 1;
}

.send-btn {
  position: absolute;
  right: 32px;
  bottom: 18px;
  min-width: 28px;
  height: 28px;
  padding: 4px;
  border-radius: 50%;
  transition: background 0.2s;
  z-index: 2;
}

.scroll-percentage-input {
  position: absolute;
  top: 5px;
  right: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 10px;
  z-index: 3;
  pointer-events: none;
}
</style>